package schedule;

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;

import static org.quartz.CronScheduleBuilder.cronSchedule;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;

/**
 * 功能描述:
 *
 * @Author: luobo
 * @Date: 2021/2/8 0008 17:27:44
 */
public class InvokeStatSchedule{
    public void start()
    {
        //开启定时器
        SchedulerFactory sf = new StdSchedulerFactory();
        try {
            Scheduler sched = sf.getScheduler();
            JobDetail job = newJob(DialogJob.class)
                    .withIdentity("job1", "group1")
                    .build();

            CronTrigger trigger = newTrigger()
                    .withIdentity("trigger1", "group1")
                    //工作日 14点45分提醒
                    .withSchedule(cronSchedule("0 45 14 0 0 1/5 "))
                    //调试用
                    //.withSchedule(cronSchedule("0/10 * * * * ? "))
                    .build();
            sched.scheduleJob(job, trigger);
            // 启动
            if (!sched.isShutdown()) {
                sched.start();
            }
            System.out.println("开启定时器");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}